<script>

import * as echarts from 'echarts';
export default {
  name: 'VisualizationFive',
  data() {
    return{
    }
  },
  mounted() {
    this.getData3();
  },
  methods: {
    getData3() {
      this.$axios.get('/api/vis/data9', {

      }).then(res =>{
        if(res.data.code === 20041) {
          let data1 = [];
          let data2 = [];
          for (let i = 0; i < 10; i++) {
            data1.push(
                res.data.data[i].param
            );
            data2.push(
                res.data.data[i].param1
            );
          }
          this.init3(data1,data2);
        }
      }).catch(error =>{
        this.open4(error);
      })
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init3(data1, data2) {
      var chartDom = document.getElementById('main5');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: "5A级景区游客分布",
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            // Use axis to trigger tooltip
            type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
          }
        },
        legend: {},
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          name: "地区",
          type: 'value'
        },
        yAxis: {
          name: "游客数",
          type: 'category',
          data: data1
        },
        series: [
          {
            // name: 'Direct',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: data2
          },
        ]
      };



      myChart.getZr().on('click', params => {
        console.log(params)
        if(params.topTarget){
          alert(params.topTarget.style.text)
        }
      })

      option && myChart.setOption(option);
    }
  }

}
</script>

<template>
  <div id="main5"></div>
</template>

<style scoped>
#main5 {
  width: 100%;
  height: 100%;
}
</style>